import { useState } from "react";
import { useNavigate,useSearchParams,useLocation } from "react-router";

function News() {

    const navigate = useNavigate();

    const [params]= useSearchParams();

     const {state:{id}}= useLocation();

     console.log(id);

    // console.log(params.get("id"));

    const [list, setList] = useState([
        { id: 1, title: "观天下·加拿大内政｜加拿大财长辞职 特鲁多面临下台." },
        { id: 2, title: "“叙利亚沙姆解放武装”领导人要求以色列撤军" }
    ])

    const showNews = (id) => {

        navigate(`/newsDetail/${id}.html`)

    }
    return (
        <div>
            新闻列表

            <div>
                {
                    list.map(item => (
                        <li onClick={() => showNews(item.id)} key={item.id}>{item.title}</li>
                    ))
                }
                <li></li>
            </div>
        </div>

    )

}
export default News;